<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
    /*
     * 多对多  获取该标签的所有文章
     */
	public function articles()
    {
        return $this->belongsToMany('App\Models\Article', 'article_tags', 'tag_id', 'article_id');
    }
    //
	public function getTag()
	{
		return $this->orderBy('weight', 'desc')->get();
	}
	
	public function getTagId($str)
	{
		$tags = explode(",", $str);
		$tag_id = $this->select('id')->whereIn('name', $tags)->get();
		$tags_id = array();
		foreach($tag_id as $k=>$v){
			$tags_id[] = $v->id;
		}
		return $tags_id;
	}
}
